package com.atguigu.tingshu.album.service.impl;

import com.atguigu.tingshu.album.mapper.BaseCategory1Mapper;
import com.atguigu.tingshu.album.mapper.BaseCategory2Mapper;
import com.atguigu.tingshu.album.mapper.BaseCategory3Mapper;
import com.atguigu.tingshu.album.mapper.BaseCategoryViewMapper;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory1;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import com.atguigu.tingshu.model.base.BaseEntity;
import com.atguigu.tingshu.vo.category.CategoryVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class BaseCategoryServiceImpl extends ServiceImpl<BaseCategory1Mapper, BaseCategory1> implements BaseCategoryService {

	@Autowired
	private BaseCategory1Mapper baseCategory1Mapper;

	@Autowired
	private BaseCategory2Mapper baseCategory2Mapper;

	@Autowired
	private BaseCategory3Mapper baseCategory3Mapper;

	@Autowired
	private BaseCategoryViewMapper baseCategoryViewMapper;


	/**
	 * 获取三级分类集合
	 * @return
	 */
    @Override
    public List<CategoryVo> getBaseCategoryList() {
        return baseCategoryViewMapper.getBaseCategoryList();
    }

	@Override
	public CategoryVo getBaseCategoryList(Long category1Id) {
		return baseCategoryViewMapper.getBaseCategoryListByC1Id(category1Id);
	}

	/**
	 * 获取该分类标签id下的属性值
	 * @param category1Id 一级分类标签id
	 * @return BaseAttribute
	 */
	@Override
	public List<BaseAttribute> findAttributeAndValue(Long category1Id) {
		return baseCategoryViewMapper.findAttributeAndValue(category1Id);
	}

	/**
	 * [rpc]
	 * 根据专辑id 获取到分类数据
	 * @param albumId 专辑id
	 * @return 分类数据
	 */
    @Override
    public BaseCategoryView getCategoryView(Long albumId) {
		return baseCategoryViewMapper.getCategoryView(albumId);
    }


	/**
	 * 获取一级分类id集合
	 * @return 一级分类id集合
	 */
    @Override
    public List<Long> getCategory1IdList() {
		List<BaseCategory1> category1List = baseCategory1Mapper.selectList(null);
        return category1List.stream().map(BaseEntity::getId).toList();
    }


}
